﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using VisualWip.Core;
using Application = System.Windows.Application;

namespace VisualWip.PresentationModel
{
    public class ColumnTypeToImageResourceConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof (ImageSource))
                throw new InvalidOperationException("Target type must be System.Windows.Media.ImageSource.");

            var columnType = value as ColumnType;
            if (columnType != null)
            {
                var imageSource =
                    Application.Current.TryFindResource(string.Format("ColumnType_{0}", columnType.Name)) as ImageSource;
                return imageSource ?? DependencyProperty.UnsetValue;
            }

            return DependencyProperty.UnsetValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}